package com.lims.admin.dao;


import javacommon.base.*;

import cn.org.rapid_framework.page.*;

import com.lims.admin.model.*;
import com.lims.admin.vo.query.*;

import static cn.org.rapid_framework.util.ObjectUtils.*;
import org.springframework.stereotype.Repository;

/**
 * 
 * @author zzh
 *
 */
@Repository @SuppressWarnings({"unchecked"})
public class MenuDao extends BaseHibernateDao<Menu,java.lang.String>{

	public Class getEntityClass() {
		return Menu.class;
	}
	
	public Page findPage(MenuQuery query) {
        //XsqlBuilder syntax,please see http://code.google.com/p/rapid-xsqlbuilder
        // [column]为字符串拼接, {column}为使用占位符. [column]为使用字符串拼接,如username='[username]',偷懒时可以使用字符串拼接 
        // [column] 为PageRequest的属性
		String sql = "select t from Menu t where 1=1 "
			  	+ "/~ and t.menuname = {menuname} ~/"
			  	+ "/~ and t.menuurl = {menuurl} ~/"
			  	+ "/~ and t.parentid = {parentid} ~/"
			  	+ "/~ and t.isleaf = {isleaf} ~/"
			  	+ "/~ and t.menulevel = {menulevel} ~/"
			  	+ "/~ and t.discribe = {discribe} ~/"
				+ " order by t.sortno ";

        //生成sql2的原因是为了不喜欢使用xsqlbuilder的同学，请修改生成器模板，删除本段的生成
        StringBuilder sql2 = new StringBuilder("select t from Menu t where 1=1 ");
        if(isNotEmpty(query.getObjid())) {
            sql2.append(" and  t.objid = :objid ");
        }
        if(isNotEmpty(query.getMenuname())) {
            sql2.append(" and  t.menuname = :menuname ");
        }
        if(isNotEmpty(query.getMenuurl())) {
            sql2.append(" and  t.menuurl = :menuurl ");
        }
        if(isNotEmpty(query.getParentid())) {
            sql2.append(" and  t.parentid = :parentid ");
        }
        if(isNotEmpty(query.getIsleaf())) {
            sql2.append(" and  t.isleaf = :isleaf ");
        }
        if(isNotEmpty(query.getMenulevel())) {
            sql2.append(" and  t.menulevel = :menulevel ");
        }
        if(isNotEmpty(query.getDiscribe())) {
            sql2.append(" and  t.discribe = :discribe ");
        }
        if(isNotEmpty(query.getSortColumns())) {
            sql2.append(" order by :sortColumns ");
        }	
        
		return pageQuery(sql,query);
	}
	

}
